<template>
  <!-- 漏洞列表 -->
  <el-table :data="tableData" :loading="loading" border="true">
    <el-table-column v-if="showSelection" type="selection" width="55" />
    <el-table-column prop="id" label="漏洞ID" width="80" />
    <el-table-column
      prop="title"
      label="名称"
      min-width="180"
    >
     <template #default="{ row }">
       <el-tooltip :content="row.title" placement="top" :show-after="1000">
        <span class="ellipsis">{{ row.title }}</span>
        </el-tooltip>
      </template>
  </el-table-column>
  
 <el-table-column
      prop="product_type"
      label="产品类型"
      width="120"
      show-overflow-tooltip
    >
      <template #default="{ row }">
        {{ row.product_type }}
      </template>
      </el-table-column>
      <el-table-column
      prop="is_standard"
      label="数据源"
      width="120"
      show-overflow-tooltip
    >
      <template #default="{ row }">
        {{ row.is_standard===1?"标准库":"预备库" }}
      </template>
      </el-table-column>

    <el-table-column
      prop="vuln_type"
      label="类型"
      width="120"
      show-overflow-tooltip
    >
      <template #default="{ row }">
        {{ formatVulnType(row.vuln_type) }}
      </template>
    </el-table-column>
    <el-table-column prop="level" label="危害等级" width="90">
      <template #default="{ row }">
        <el-tag :type="getTagType(row.level)">{{ row.level }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="score" label="评分" width="80" />
    <el-table-column prop="poc_list" label="poc/exp文件数量" width="90">
      <template #default="{ row }">
        {{ row.poc_list?.length }}
      </template>
    </el-table-column>
    <el-table-column prop="publish_time" label="发布时间" width="160" />

    <!-- 操作按钮插槽 -->
    <slot name="optSlot" />
  </el-table>
</template>

<script setup>
const props = defineProps({
  tableData: {
    type: Array,
    default: [],
  },
  loading: {
    type: Boolean,
    default: false,
  },
  showSelection: {
    type: Boolean,
    default: true,
  },
});
const level_list = ref({
  低: "warning",
  中: "warning",
  高: "danger",
  严重: "danger",
});
// 格式化类型
const formatVulnType = (type) => {
  const typeMap = {
    rce: "RCE",
    "privilege-escalation": "权限提升",
    "auth-bypass": "认证绕过",
    "info-leak": "信息泄露",
  };
  return typeMap[type] || type;
};

// 获取标签类型
const getTagType = (level) => {
  return level_list.value[level] || "";
};
</script>

<style lang="scss" scoped></style>
